package is2.minga.packetizerDistributor;


import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.BlockingQueue;

public class DistributorConnectionAccepter implements Runnable
{
	BlockingQueue<MsgDistributor> colaMsj;
	Integer inPort;
	Integer tipoMensaje;
	
	DistributorConnectionAccepter(BlockingQueue<MsgDistributor> colaMsj, Integer inPort, Integer tipoMensaje)
	{
		this.colaMsj = colaMsj;
		this.inPort = inPort;
		this.tipoMensaje = tipoMensaje;
	}
	
	public void run()
	{

		try 
		{

			ServerSocket welcomeSocket;
			welcomeSocket = new ServerSocket(inPort);
	
				
			while (true)
			{
				
				Socket connectionSocket = welcomeSocket.accept(); 
	
				MsgDistributor msg = new MsgDistributor();
				
				msg.tipo = tipoMensaje;
				msg.socket = connectionSocket;
				colaMsj.put(msg);
			}
	
		} catch (Exception e) 	{
			System.out.println(e.toString());
			
		}
	
	}

}
